SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROC [dbo].[SP_TASALD_EMPR_Q16]
/*---------------------------------------------------------------------*/
/*----- Empresa       : OFISIS S.A.                            -----*/
/*----- Cliente          : OFISIS S.A.                         	  -----*/
/*----- Sistema        : Contabilidad                           -----*/
/*----- Modulo         : Empresa                                -----*/
/*----- Programa      : Reporte de ajuste por inflacion        -----*/ 
/*----- Nombre         : SP_TASALD_EMPR_Q16                	  -----*/
/*----- Script            : TASALD_EMPR                            -----*/
/*----- Desarrollado por : Betsy Sanchez Arenas                   -----*/
/*----- Fecha  Creaci?n          : 11/10/1997                             -----*/
/*----- Base de Datos  : MS SQL Server                          -----*/
/*----- Version BD       : 8.0                                    -----*/
/*----- Invoca a SP      :                                        -----*/
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/*----- Modificado 1 por : Martin Garcia Farfan                   -----*/
/*----- Fecha Modifica   : 12/03/1999                             -----*/
/*----- Detalle Modifica : Estandarizacion                        -----*/
/*-------------------------------------------------------------------------------------------*/
/*----- Modificado 2 por : Marco Acua Paredes                  -----*/
/*----- Fecha Modifica   : 25/09/2002                             -----*/
/*----- Detalle Modifica :  Modificaci?n de Cursor  - Nueva Versi?n -----*/
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/*----- Drop Proc SP_TASALD_EMPR_Q16                              -----*/
/*----- Grant Execute On SP_TASALD_EMPR_Q16 To PUBLIC             -----*/
/*----- SP_TASALD_EMPR_Q16   '01' ,1, 2002 , 9 , '42101' , 5                         	  -----*/
/*---------------------------------------------------------------------*/
@ISCO_EMPR           	TD_VC_002,
@INNU_CNTB_EMPR 	TD_IN_001_CONT,
@INNU_ANNO            	TD_IN_004_ANNO,
@INNU_MESE            	TD_IN_002_MESE,
@ISCO_CNTA           	TD_VC_020_CNTA,
@INNV_INFO_CNTA 	TD_IN_001
As
Select  t1.CO_CNTA_EMPR, max(t2.DE_CNTA_EMPR),	max(t2.ST_CNTA_NATU),convert(char(4),max(t1.NU_ANNO)) + '-' + 
	substring(convert(char(3),max(NU_MESE)+100),2,3), 
	(Isnull(sum(Isnull(t1.IM_CARG_CNTB, 0)), 0) - Isnull(sum(Isnull(t1.IM_ABON_CNTB, 0)), 0))
 From TASALD_EMPR t1
   Left Outer Join TMPLAN_EMPR t2
   On t1.CO_EMPR = t2.CO_EMPR
   And  t1.CO_CNTA_EMPR = t2.CO_CNTA_EMPR
   And  t2.NU_ANNO = 9999
 Where t1.CO_EMPR      = @ISCO_EMPR
  	And  t1.NU_CNTB_EMPR = @INNU_CNTB_EMPR
   	And  t1.NU_ANNO      = @INNU_ANNO
   	And  t1.NU_MESE      <= @INNU_MESE
   	And  t1.CO_CNTA_EMPR like Rtrim(@ISCO_CNTA)+'%' 
   	And  datalength(rtrim(t1.CO_CNTA_EMPR)) = @INNV_INFO_CNTA
   	And  t1.TI_AUXI_EMPR IS null
   	And  t1.CO_AUXI_EMPR IS null
   	And  t1.CO_ORDE_SERV IS null
 Group By t1.CO_CNTA_EMPR
 Order By t1.CO_CNTA_EMPR
Return
/*--------------------------------- Fin -----------------------------------------*/


GO
